import { getFormatDate } from '@/utils/common';

export interface Pagination {
    pageSize: number;
    pageNum: number;
    total: number;
}

export interface TargetForm {
    date: string;
}

export interface TargetQuery extends TargetForm, Pagination {
    type: string;
    groupCode: string;
    userCode: string;
}
export interface TargetuserSearch {
    departCode: string;
    goalType: number;
    month: string;
    name: string;
    year: string;
}

export interface DatePickerConfig {
    type: string;
    placeholder: string;
    format: string;
    valueFormat: string;
}

export interface TargetPageConfig {
    datePicker?: DatePickerConfig;
    columns: Object[];
    totalInfo: string;
    showTotalTips: boolean;
    showSearchForm: boolean;
    showImportButton: boolean;
    canEditAmount: boolean;
}

export class TargetPagesConfig {
    // 全年业绩
    static yearlyPerformance: TargetPageConfig = {
        datePicker: {
            type: 'year',
            placeholder: '请选择年份',
            format: 'YYYY年',
            valueFormat: 'YYYY-M',
        },
        columns: [
            {
                label: '年份',
                key: 'year',
                render: true,
                prop: {
                    minWidth: '150px',
                },
            },
            {
                label: '员工姓名',
                key: 'userName',
                prop: {
                    minWidth: '120px',
                },
            },
            {
                label: '工号',
                key: 'userCode',
                prop: {
                    minWidth: '100px',
                },
            },
            {
                label: '全年目标签约（单位：万元）',
                key: 'goalSignAmount',
                prop: {
                    minWidth: '180px',
                },
                render: true,
            },
            {
                label: '全年实际签约（单位：万元）',
                key: 'actualSignAmount',
                prop: {
                    minWidth: '180px',
                },
            },
            {
                label: '完成率',
                key: 'finishRate',
                prop: {
                    minWidth: '110px',
                },
            },
        ],
        totalInfo:
            '全年总目标签约：<span>#GOAL#</span>万元&nbsp;&nbsp;&nbsp;&nbsp;全年总实际签约：<span>#ACTUAL#</span>万元&nbsp;&nbsp;&nbsp;&nbsp;完成率：<span>#RATE#</span>',
        showTotalTips: true,
        showSearchForm: true,
        showImportButton: true,
        canEditAmount: true,
    };
    // 本月业绩
    static monthlyPerformance: TargetPageConfig = {
        datePicker: {
            type: 'month',
            placeholder: '请选择月份',
            format: 'YYYY年M月',
            valueFormat: 'YYYY-M',
        },
        columns: [
            {
                label: '月份',
                key: 'month',
                render: true,
                prop: {
                    minWidth: '150px',
                },
            },
            {
                label: '员工姓名',
                key: 'userName',
                prop: {
                    minWidth: '120px',
                },
            },
            {
                label: '工号',
                key: 'userCode',
                prop: {
                    minWidth: '100px',
                },
            },
            {
                label: '本月目标签约（单位：万元）',
                key: 'goalSignAmount',
                prop: {
                    minWidth: '180px',
                },
                render: true,
            },
            {
                label: '本月实际签约（单位：万元）',
                key: 'actualSignAmount',
                prop: {
                    minWidth: '180px',
                },
            },
            {
                label: '完成率',
                key: 'finishRate',
                prop: {
                    minWidth: '110px',
                },
            },
        ],
        totalInfo:
            '本月总目标签约：<span>#GOAL#</span>万元&nbsp;&nbsp;&nbsp;&nbsp;本月总实际签约：<span>#ACTUAL#</span>万元&nbsp;&nbsp;&nbsp;&nbsp;完成率：<span>#RATE#</span>',
        showTotalTips: true,
        showSearchForm: true,
        showImportButton: true,
        canEditAmount: true,
    };
    // 回款
    static backPayment: TargetPageConfig = {
        columns: [
            {
                label: '员工姓名',
                key: 'userName',
                prop: {
                    minWidth: '120px',
                },
            },
            {
                label: '工号',
                key: 'userCode',
                prop: {
                    minWidth: '100px',
                },
            },
            {
                label: '实际签约（单位：万元）',
                key: 'goalSignAmount',
                prop: {
                    minWidth: '150px',
                },
                render: true,
            },
            {
                label: '已回款（单位：万元）',
                key: 'actualSignAmount',
                prop: {
                    minWidth: '150px',
                },
            },
            {
                label: '完成率',
                key: 'finishRate',
                prop: {
                    minWidth: '110px',
                },
            },
        ],
        totalInfo:
            '总回款：<span>#GOAL#</span>万元&nbsp;&nbsp;&nbsp;&nbsp;本年总实际签约：<span>#ACTUAL#</span>万元&nbsp;&nbsp;&nbsp;&nbsp;完成率：<span>#RATE#</span>',
        showTotalTips: false,
        showSearchForm: false,
        showImportButton: false,
        canEditAmount: false,
    };
    // 全年上刊
    static yearlyPublish: TargetPageConfig = {
        datePicker: {
            type: 'year',
            placeholder: '请选择年份',
            format: 'YYYY年',
            valueFormat: 'YYYY-M',
        },
        columns: [
            {
                label: '年份',
                key: 'year',
                render: true,
                prop: {
                    minWidth: '150px',
                },
            },
            {
                label: '员工姓名',
                key: 'userName',
                prop: {
                    minWidth: '120px',
                },
            },
            {
                label: '工号',
                key: 'userCode',
                prop: {
                    minWidth: '100px',
                },
            },
            {
                label: '实际上刊（单位：万元）',
                key: 'actualSignAmount',
                prop: {
                    minWidth: '150px',
                },
                render: true,
            },
        ],
        totalInfo: '本年总实际上刊：<span>#ACTUAL#</span>万元',
        showTotalTips: false,
        showSearchForm: true,
        showImportButton: false,
        canEditAmount: false,
    };
    // 本月上刊
    static monthlyPublish: TargetPageConfig = {
        datePicker: {
            type: 'month',
            placeholder: '请选择月份',
            format: 'YYYY年M月',
            valueFormat: 'YYYY-M',
        },
        columns: [
            {
                label: '月份',
                key: 'month',
                render: true,
                prop: {
                    minWidth: '150px',
                },
            },
            {
                label: '员工姓名',
                key: 'userName',
                prop: {
                    minWidth: '120px',
                },
            },
            {
                label: '工号',
                key: 'userCode',
                prop: {
                    minWidth: '100px',
                },
            },
            {
                label: '实际上刊（单位：万元）',
                key: 'actualSignAmount',
                prop: {
                    minWidth: '150px',
                },
                render: true,
            },
        ],
        totalInfo: '本月总实际上刊：<span>#ACTUAL#</span>万元',
        showTotalTips: false,
        showSearchForm: true,
        showImportButton: false,
        canEditAmount: false,
    };
}

export interface TargetItem {
    id?: string;
    year?: number | string; // 年份
    month?: number | string; // 月份
    userName?: string; // 员工姓名
    userCode?: string; // 员工工号
    goalSignAmount?: number; // 目标签约
    actualSignAmount?: number; // 实际签约
    backedAmount?: number; // 回款金额
    goalSignMouthAmount?: number | string;
    finishRate?: number | string; // 完成率
    createTime?: string; // 创建时间
    updateTime?: string; // 更新时间
    createUser?: number; // 创建人id
    updateUser?: number; // 更新人id
    joinTraderCode?: string; // 供应商编码
}

export interface TargetLogItem {
    date: string; // 操作时间
    operator: string; // 操作人
    content: string; // 操作明细
    file: string | null; // 附件
    fileName: string | null; // 附件名称
}
export interface TargetSetForm {
    userCode: string; // 新建员工
    goalSignAmount: string; // 全年签约目标
    goalSignMouthAmount: string; // 全月签约目标
    joinTraderCode: string;
    year: string | number;
    month: string | number;
}

export class TargetPage {
    // 查询参数model
    query: TargetQuery = {
        type: '1', // 默认全年业绩
        groupCode: '', // 默认为空
        userCode: '', // 默认为空
        date: getFormatDate('', 'YYYY-mm-dd'), // 默认当前日期
        pageNum: 1,
        pageSize: 10,
        total: 0,
    };
    userSearch: TargetuserSearch = {
        departCode: '',
        goalType: 0,
        month: '',
        name: '',
        year: '',
    };

    // 列表数据
    list: TargetItem[] = [];
    // 页面配置信息
    config: TargetPageConfig = TargetPagesConfig.yearlyPerformance;
    // 是否显示加载视图
    loading = false;

    // 是否显示编辑弹窗的加载视图
    editLoading = false;

    // 是否显示导入弹窗
    importDialogVisible = false;
    // 是否显示导入弹窗加载视图
    importLoading = false;
    // 允许导入的文件类型
    limitTypes: string[] = ['xls', 'xlsx', 'csv'];
    // 上传到obs的文件url
    fileObsUrl = '';

    // 是否显示日志列表弹窗
    targetDialogVisible = false;
    targetForm: TargetSetForm = {
        userCode: '',
        goalSignAmount: '',
        goalSignMouthAmount: '',
        joinTraderCode: '',
        year: '',
        month: '',
    };

    // 是否显示日志列表弹窗
    logsDialogVisible = false;
    // 日志查询参数model
    logsPagination: Pagination = {
        pageNum: 1,
        pageSize: 10,
        total: 0,
    };
    // 是否显示显示列表加载视图
    logsLoading = false;
    // 日志列表
    logs: TargetLogItem[] = [];
    // 日志列表表头
    logsColumns: Object[] = [
        {
            label: '操作时间',
            key: 'date',
            prop: {
                width: '210px',
            },
        },
        {
            label: '操作人',
            key: 'operator',
            prop: {
                width: '150px',
            },
        },
        {
            label: '操作明细',
            key: 'content',
        },
        {
            label: '附件',
            key: 'file',
            render: true,
            prop: {
                width: '120px',
            },
        },
    ];
}

export class TipsDialog {
    show = false;
    // 列表表头
    columns: Object[] = [
        {
            label: '序号',
            key: 'index',
            render: true,
            prop: {
                width: '100px',
            },
        },
        {
            label: '名词',
            key: 'name',
            prop: {
                width: '160px',
            },
        },
        {
            label: '名词解释',
            key: 'content',
        },
    ];
    // 列表数据
    list: Object[] = [
        {
            index: '1',
            name: '全年业绩',
            content: '当前自然年，从1月1日至今，本年度已归档签约金额 / 本年目标签约；',
        },
        {
            index: '2',
            name: '本月业绩',
            content: '当前自然月，从本月1日至今，本月度已归档签约金额 / 本月目标签约；',
        },
        {
            index: '3',
            name: '回款率',
            content: '截至目前，历史累计回款金额之和 / 已归档签约金额之和；',
        },
        {
            index: '4',
            name: '全年上刊',
            content: '当前自然年，从1月1日至昨日，本年度历史累计方案金额；',
        },
        {
            index: '5',
            name: '本月上刊',
            content: '当前自然月，从本月1日至昨日，本月度历史累计方案金额；',
        },
    ];
}
